
local ClassRef = app.mvc.createRenderClass(...)

function ClassRef.createWithData(data, node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.TalentIcon))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end

function ClassRef.create(node)
	return ClassRef.createWithData(nil, node)
end

function ClassRef:init(data)
	self.super.init(self, data)

    self:setSelected(false)
    
	display.uiAddClick(self._ui.Panel, function(sender, eventType)
        if self._data and not self:isSelected() then
    		executeFunc(self._onClick, self)
        end
	end)

	self:refresh()
end

-- data Talent
function ClassRef:refresh()
	if self._data then
		local talent = self._data

        self._ui.icon:loadTexture(talent:getIcon())
        self:setActive(talent:isActive())
        self:setCanLearn(talent:canActive())
	end
end

function ClassRef:setActive(a)
	self._ui.light:setVisible(a)
	self._ui.mask:setVisible(not a)
end

function ClassRef:setSelected(s)
	self._ui.selected:setVisible(s)
end

function ClassRef:isSelected()
	return self._ui.selected:isVisible()
end

function ClassRef:setCanLearn(b)
	self._ui.sens:setVisible(b)
	self._ui.icon_add:setVisible(b)
end

function ClassRef:onBtnClick(cb)
	self._onClick = cb
end

return ClassRef
